<?php
class new_model extends jqxGrid_CI_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    
    function get($id)
    {
        $query = $this->db->query("
            SELECT * 
            FROM `dtb_new` 
            WHERE `delete` is null
                AND `id`='$id'
        ");
        return $query->result();
    }
    function getByFoot($ca="")
    {
        $query = $this->db->query("
            SELECT * 
            FROM `dtb_new` 
            WHERE `delete` is null
                AND `category`='$ca'
                AND `infoot`=1
        ");
        return $query->result();
    }
    function delete($id){
        $query = "
            UPDATE `dtb_new` 
            SET `delete` = now()
            WHERE `id`='$id'
        ";
        $this->db->query($query);
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
        
    }
    
    function restore($id){
        $query = "
            UPDATE `dtb_new` 
            SET     `delete`    =   null
            WHERE   `id`        =   '$id'
        ";
        $this->db->query($query);
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    
    function changeStatus($id,$status){
        $query = "
            UPDATE `dtb_new` 
            SET `status`    =   '$status',
                `update`    =   now()
            WHERE `id`='$id'
        ";
        $this->db->query($query);
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    
    function insert($params){
        $this->db->set('insert', 'NOW()', FALSE);
        $this->db->insert('dtb_new', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($id,$params){
        $this->db->where(array('id'=> $id,'delete'=> null));
        //$this->db->where('delete', 'is null',FALSE);
        $this->db->set('update', 'NOW()', FALSE);
        $this->db->update('dtb_new', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function gettotal_rows(){
        $configs["strQuery"]="
            SELECT SQL_CALC_FOUND_ROWS `dtb_new`.*
            FROM `dtb_new` 
            ";
        $configs["strWhere"]="
            WHERE true
            ";
        $configs["strOrderBy"]=" ORDER BY `dtb_new`.`insert` DESC";
        $configs["fields"]=array(
            "Product"=>"`ProductID`"
            );
        $configs["usinglimit"]=true;
        $this->init($configs);
        return $this->jqxBinding();
//        $strQuery="
//            SELECT SQL_CALC_FOUND_ROWS `dtb_new`.*
//            FROM `dtb_new` 
//            WHERE true 
//            ";
//        $fields=array(
//            
//        );
//        $this->__new($strQuery,"",$fields);
//        return $this->jqxBinding();
    }
    
    
    
}
?>
